<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>宇成建筑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../statics/css/font.css">
    <link rel="stylesheet" href="../statics/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="../statics/css/xadmin.css">
    <link rel="stylesheet" href="../statics/css/style.css">
</head>

<body class='labelAuto'>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="welcome.html">首页</a>
            <a href="javascript:;">供应商管理</a>
            <a>
                <cite>供应商列表</cite>
            </a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
            onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
        </a>
    </div>
    <div class="layui-fluid">
        <div class="layui-d layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body search">
                        <form action="" class="layui-form livingList">
                            <div class="layui-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">搜索</label>
                                    <div class="layui-input-block">
                                        <input type="search" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <button class="layui-btn search" type="button" id='search'>
                                        <i class="iconfont layui-icon">&#xe615;</i>
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="layui-card-body tableCardBody">
                        <table class="layui-table" id="lists" lay-filter="test"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script src="../statics/plugins/layui/layui.js" charset="utf-8"></script>
<script src='../statics/plugins/jQuery-3.2.1/jquery-3.2.1.min.js'></script>
<script type="text/javascript" src="../statics/plugins/X-admin/xadmin.js"></script>
<script type="text/javascript" src="../statics/js/public.js?v=1129"></script>
<script type='text/html' id='toolbar'>
    <button class="layui-btn add" type="button" auth="addSupplier">
        添加
    </button>
</script>
<script type="text/javascript">
    layui.use(['form', 'layer', "table", "laydate"], function () {
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        var layer = layui.layer;
        var projectId=Number(localStorage.getItem('constructionLedgerZaGong_id'));
			var sectionId = Number(localStorage.getItem('fz_id1'));//楼层ID
        // 异步数据加载
        var lists = table.render({
            elem: '#lists', //绑定DOM元素
            id: 'lists', //table的id
            title: '人员列表',
            height: 'full-150',
            contentType: "application/json; charset=utf-8",
            url: url + '/hrm/supplier/lists', //数据接口地址
            request: {
                pageName: 'page', //页码的参数名称，默认：page
                limitName: 'length' //每页数据量的参数名，默认：limit
            },
            method: 'POST',
            parseData: function(res){
				return {
					"code": res.code, //解析接口状态
                    "data": res.data.data,
                    "msg": res.msg,
                    "count":res.data.count
				};
            },
            where: {
                search: "",
                token:getToken()
            },
            toolbar: '#toolbar',
            defaultToolbar: ['filter'],
            page: true, //开启分页
            limit: 10, //默认每页记录条数
            limits: [10, 20, 50], //每页记录条数可选数量
            cols: [
                [ //表头
                    { field: '', title: '编号', type: 'numbers',width:'8%'},
                    { field: 'code', title: '供应商编码', width:'9%'},
                    { field: 'name', title: '供应商名称', },
                    { field: 'liaison', title: '联系人',width:'8%' },
                    { field: 'phone', title: '联系方式',width:'10%'},
                    { field: 'address', title: '公司地址',width:'20%'},
                    { field: 'accountBank', title: '开户行'},
                    { field: '', title: '操作',width:"10%",templet(d){
                        return `
                            <button class='bianji layui-btn' data-id=${d.id} auth="editSupplier" lay-event="bianji">编辑</button>
                        `
                    }}
                ]
            ],
            response: {
                statusName: 'code', //数据状态的字段名称，默认：code
                statusCode: 100000, //成功的状态码，默认：0
                msgName: 'msg', //状态信息的字段名称，默认：msg
                countName: 'count', //数据总数的字段名称，默认：count
                dataName: 'data' //数据列表的字段名称，默认：data
            },
            done:function(){
                permission();
            }
        });
        table.on('tool(test)',function(data){
            if(data.event=="bianji"){
                layer.open({
                    type: 1,
                    title: "编辑",
                    area: ['40%', 'auto'],
                    content: `
                        <form class='layui-form layerOpen'>
                            <div class="layui-item">
                                <div class='layui-inline'>
                                    <label class="layui-form-label">供应商名称</label>
                                    <div class="layui-input-block">
                                        <input type="text" class="layui-input" id="name" value=${data.data.name}>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-item">
                                <div class='layui-inline'>
                                    <label class="layui-form-label">联系人</label>
                                    <div class="layui-input-block">
                                        <input type="text" class="layui-input" id="liaison" value=${data.data.liaison}>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-item">
                                <div class='layui-inline'>
                                    <label class="layui-form-label">联系方式</label>
                                    <div class="layui-input-block">
                                        <input type="text" class="layui-input" id="phone"  value=${data.data.phone}>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-item">
                                <div class='layui-inline'>
                                    <label class="layui-form-label">公司地址</label>
                                    <div class="layui-input-block">
                                        <input type="text" class="layui-input" id="address"  value=${data.data.address}  onmouseover="this.title=this.value" title="">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-item">
                                <div class='layui-inline'>
                                    <label class="layui-form-label">开户名称</label>
                                    <div class="layui-input-block">
                                        <input type="text" class="layui-input" id="accountName" value=${data.data.accountName} onmouseover="this.title=this.value" title="">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-item">
                                <div class='layui-inline'>
                                    <label class="layui-form-label">开户银行</label>
                                    <div class="layui-input-block">
                                        <input type="text" class="layui-input" id="accountBank" value=${data.data.accountBank} onmouseover="this.title=this.value" title="">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-item">
                                <div class='layui-inline'>
                                    <label class="layui-form-label">开户账号</label>
                                    <div class="layui-input-block">
                                        <input type="text" class="layui-input" id="accountNumber" value=${data.data.accountNumber} onmouseover="this.title=this.value" title="">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-item">
                                <div class='layui-inline'>
                                    <label class="layui-form-label">法定代表人</label>
                                    <div class="layui-input-block">
                                        <input type="text" class="layui-input" id="corporation" value=${data.data.corporation} >
                                    </div>
                                </div>
                            </div>
                        </form>
                    `,
                    btn: ['确认', '取消'],
                    skin: 'my-skin',
                    yes: function(index, layero) {
                        var name = $('#name').val();
                        var phone = $('#phone').val();
                        var liaison = $('#liaison').val();
                        var address = $('#address').val();
                        var accountName = $('#accountName').val();
                        var accountBank = $('#accountBank').val();
                        var accountNumber = $('#accountNumber').val();
                        var corporation = $('#corporation').val();
                        $.ajax({
                            url: url + "/hrm/supplier/edit",
                            type: "POST",
                            async: false,
                            data: {
                                id: data.data.id,
                                name: name,
                                phone: phone,
                                liaison: liaison,
                                address: address,
                                accountName: accountName,
                                accountBank: accountBank,
                                accountNumber: accountNumber,
                                corporation: corporation,
                                token:$.parseJSON(localStorage.getItem('login_msg')).token
                            },
                            success: function(r) {
                                if(r.code == 100000) {
                                    tips('编辑供应商',r);
                                    setTimeout(function(){
                                        layer.closeAll();
                                        table.reload('lists');
                                    },2000);
                                } else {
                                    tips('编辑供应商',r);
                                }
                            }
                        })
                    }
                })
            }
        })

        $('body').on('click','#search',function(){
            var search=$(this).parent().prev().find('input').val();
            table.reload('lists',{
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where:{
                    search:search,
                    token:getToken()
                }
            })
        })
        $('body').on('click', '.add', function() {
            var id = Number($(this).data('id'));
            layer.open({
                type: 1,
                title: "编辑",
                area: ['40%', 'auto'],
                content: `
                    <form class='layui-form layerOpen'>
                        <div class="layui-item">
                            <div class='layui-inline'>
                                <label class="layui-form-label">供应商名称</label>
                                <div class="layui-input-block">
                                    <input type="text" class="layui-input" id="name">
                                </div>
                            </div>
                        </div>
                        <div class="layui-item">
                            <div class='layui-inline'>
                                <label class="layui-form-label">联系人</label>
                                <div class="layui-input-block">
                                    <input type="text" class="layui-input" id="liaison">
                                </div>
                            </div>
                        </div>
                        <div class="layui-item">
                            <div class='layui-inline'>
                                <label class="layui-form-label">联系方式</label>
                                <div class="layui-input-block">
                                    <input type="text" class="layui-input" id="phone">
                                </div>
                            </div>
                        </div>
                        <div class="layui-item">
                            <div class='layui-inline'>
                                <label class="layui-form-label">公司地址</label>
                                <div class="layui-input-block">
                                    <input type="text" class="layui-input" id="address"  onmouseover="this.title=this.value" title="">
                                </div>
                            </div>
                        </div>
                        <div class="layui-item">
                            <div class='layui-inline'>
                                <label class="layui-form-label">开户名称</label>
                                <div class="layui-input-block">
                                    <input type="text" class="layui-input" id="accountName" onmouseover="this.title=this.value" title="">
                                </div>
                            </div>
                        </div>
                        <div class="layui-item">
                            <div class='layui-inline'>
                                <label class="layui-form-label">开户银行</label>
                                <div class="layui-input-block">
                                    <input type="text" class="layui-input" id="accountBank" onmouseover="this.title=this.value" title="">
                                </div>
                            </div>
                        </div>
                        <div class="layui-item">
                            <div class='layui-inline'>
                                <label class="layui-form-label">开户账号</label>
                                <div class="layui-input-block">
                                    <input type="text" class="layui-input" id="accountNumber" onmouseover="this.title=this.value" title="">
                                </div>
                            </div>
                        </div>
                        <div class="layui-item">
                            <div class='layui-inline'>
                                <label class="layui-form-label">法定代表人</label>
                                <div class="layui-input-block">
                                    <input type="text" class="layui-input" id="corporation">
                                </div>
                            </div>
                        </div>
                    </form>
                `,
                btn: ['确认', '取消'],
                skin: 'my-skin',
                yes: function(index, layero) {
                    var name = $('#name').val();
                    var phone = $('#phone').val();
                    var liaison = $('#liaison').val();
                    var address = $('#address').val();
                    var accountName = $('#accountName').val();
                    var accountBank = $('#accountBank').val();
                    var accountNumber = $('#accountNumber').val();
                    var corporation = $('#corporation').val();
                    $.ajax({
                        url: url + "/hrm/supplier/add",
                        type: "POST",
                        async: false,
                        data: {
                            name: name,
                            phone: phone,
                            liaison: liaison,
                            address: address,
                            accountName: accountName,
                            accountBank: accountBank,
                            accountNumber: accountNumber,
                            corporation: corporation,
                            token:getToken()
                        },
                        success: function(r) {
                            if(r.code == 100000) {
                                tips('添加供应商',r);
                                setTimeout(function(){
                                    layer.closeAll();
                                    table.reload('lists');
                                },2000)
                            } else {
                                tips('添加供应商',r);
                            }
                        }
                    })
                }
            })
        })
    });
</script>

</html>